<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */

session_start();

require_once '../config.php';

if (!isset($_SESSION['rank']) || $_SESSION['rank'] < 2 || intval($_SESSION['admin']) != 1) {
    echo '<meta http-equiv="refresh" content="1;url=login.php">';
    die();
}

include '../libs/Framework/System.php';

$_system = new System();

foreach (glob("../libs/Framework/*.php") as $lib) {
    if ($lib != '../libs/Framework/System.php') {
        require_once ($lib);
    }
}

foreach (glob("../libs/Framework/HTML/*.php") as $lib) {
    require_once ($lib);
}

require '../libs/getUserDataFromDB.php';
require '../libs/getUsernameFromDB.php';
require '../libs/getCategoryName.php';
require '../libs/getTitleOfArticle.php';
require '../libs/dirlist.php';
require '../libs/getSectionName.php';
require '../libs/rank2text.php';

$Roar = array();
$log = new Log('database');

Registry::set('db', $GLOBALS['db']);
$db = $GLOBALS['db'];
Registry::set('log', $log);

define('ADMIN_LOADED', true);

$ranks = array(
                Lang::getBack('com_user', 'anonymous') => '0', 
                Lang::getBack('com_user', 'logged') => '1', 
                Lang::getBack('com_user', 'moderator') => '2', 
                Lang::getBack('com_user', 'editor') => '3', 
                Lang::getBack('com_user', 'administrator') => '4' 
                );

function getPermission($com)
{
    $query = Registry::get('db')->query("SELECT backend FROM {prefix}permissions WHERE component = 'com_" .
        $com . "'");
    $query = $query->fetch_array();
    return intval($query[0]);
}

function messageBox($text)
{
    global $Roar;
    $event = 'roar.alert(\'Status\', \''.$text.'\');';
    array_push($Roar, $event);
}

#Menu sets

$administrator = array('index.php' => Lang::getBackGlobal('overview'), 'index.php?p=build' =>
    Lang::getBackGlobal('build'), 'index.php?p=components' => Lang::getBackGlobal('components'), 'index.php?p=modules' =>
    Lang::getBackGlobal('modules'), 'index.php?p=permissions' => Lang::getBackGlobal('permissions'),
    'index.php?p=setting' => Lang::getBackGlobal('setting'), 'index.php?p=install' => Lang::getBackGlobal('install'),
    'index.php?p=log' => Lang::getBackGlobal('log'), 'index.php?p=filemanager' => Lang::getBackGlobal('files'),
    'index.php?p=tools' => Lang::getBackGlobal('tools'));

$editor = array('index.php' => Lang::getBackGlobal('overview'), 'index.php?p=build' =>
    Lang::getBackGlobal('build'), 'index.php?p=components' => Lang::getBackGlobal('components'), 'index.php?p=modules' =>
    Lang::getBackGlobal('modules'), 'index.php?p=filemanager' => Lang::getBackGlobal('files'));

$moderator = array('index.php' => Lang::getBackGlobal('overview'), 'index.php?p=components' =>
    Lang::getBackGlobal('components'));

#Menu switch

switch ($_SESSION['rank']) {
    case 2:
        $menu = $moderator;
        break;
    case 3:
        $menu = $editor;
        break;
    case 4:
        $menu = $administrator;
        break;
}
?>